<template>
  <div>
    <my-header :data="headerData"/>
    <el-row v-if="photoList.length === 0">
        <el-col :span="24" class="center">
          <el-alert title="此用户图库为空，请联系工作人员" center type="warning" show-icon :closable="false"> </el-alert>
        </el-col>
      </el-row>
    <el-row style="padding:10px;">
      <el-col :span="6" v-for="(item,index) in photoList" :key="index" style="margin-top:20px">
        <el-card :body-style="{ padding: '0px' }" shadow="hover">
            <van-image
              width="100%"
              height="200"
              fit="cover"
              :src="item.imgUrl"
            />
          <div style="padding: 14px;">
            <span>{{item.goods_name}}</span>
            <div class="bottom clearfix">
              <time class="time">{{item.add_time | timeFilter}}</time>
              <el-button type="text" class="button" @click="toWall(item.goods_id,index)">查看图库</el-button>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import myHeader from '@/components/header/index.vue'
export default {
  components: {
    'my-header': myHeader
  },
  data() {
    return {
      headerData: [
        {
          path: '/',
          value: '首页'
        },
        {
          path: '/user',
          value: '客户中心'
        }
      ],
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 100
      },
      // 照片列表数据
      goodsList: [],
      // 获取后的数据
      photoList: [],

      // 照片的总数
      total: 0
    }
  },
  filters: {
    timeFilter(value) {
      var date = new Date(value)
      var YY = date.getFullYear()
      var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1)
      var DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate())
      return YY + '年' + MM + '月' + DD + '日'
    }
  },
  mounted() {
    this.getGoodsList()
  },
  methods: {
    toWall(id, index) {
      this.$router.push(`/user/show?id=${id}&name=${this.goodsList[index].goods_name}`)
    },
    async getGoodsList(page = this.queryInfo.pagenum) {
      this.queryInfo.query = window.sessionStorage.getItem('username')
      this.queryInfo.pagenum = page
      // debugger
      const { data } = await this.$http.get(`goods`, { params: this.queryInfo })
      if (data.meta.status !== 200) return this.$message.error('获取照片列表失败')
      this.goodsList = data.data.goods
      // console.log(this.goodsList, '=====获取到的照片列表')
      // 查看对应照片库的对应图片的第一张作为首页显示
      // debugger
      for (var i in this.goodsList) {
        const { data } = await this.$http.get(`goods/${this.goodsList[i].goods_id}`)
        // console.log(data, '=====图片data')
        if (data.data.pics.length === 0) {
          this.goodsList[i].imgUrl = '#'
        } else {
          this.goodsList[i].imgUrl = data.data.pics[0].pics_big_url
        }
      }
      this.photoList = this.goodsList
    }
  }
}
</script>
<style lang="less" scoped>
.header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
/deep/.el-card {
  border-radius: 20px;
  margin-right:20px;
  .time {
    font-size: 13px;
    color: #999;
  }
  .bottom {
    margin-top: 13px;
    line-height: 12px;
  }
  .button {
    padding: 0;
    float: right;
  }
  .clearfix:before,
  .clearfix:after {
    display: table;
    content: '';
  }
  .clearfix:after {
    clear: both;
  }

}
/deep/.el-card:hover{
  transform: translateY(-5px);
  box-shadow: 4px 4px 15px  rgb(211, 210, 210) !important;
  transition: 0.5s;
}
/deep/.image-slot{
  width: 100%;
  height: 200px;
  display:flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  background: #e9e9e9;
  color:#999;
}
</style>
